package mx.com.initzero.ecommerce.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import mx.com.initzero.ecommerce.service.SearchService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
/**
 * 
 * @author HFS
 *
 */
@Controller
@RequestMapping("search")
public class SearchController {
	
	@Autowired
	private SearchService searchService;
	
	@RequestMapping(value="goBuscar",method=RequestMethod.POST)
	public void goBuscar(HttpServletRequest request){
		
		System.out.println(request.getParameter("txtSearch"));
		
	}
	
	@RequestMapping(value="getdata", method = RequestMethod.GET)
	@ResponseBody
	public List obtenerDatos(@RequestParam String term /*@RequestParam String txtSearch*/){
		
		 return searchService.listarAutoComplete(term);
		
	}
	/**
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping("getProductos")
	@ResponseBody
	public List getProduct(HttpServletRequest request){
		System.out.println(searchService.listarAutoComplete(request.getParameter("search")));
		return searchService.listarAutoComplete(request.getParameter("search"));
	
	}
	
	@RequestMapping("productos")
	public ModelAndView buscarProductos(@RequestParam String busqueda){
		
		return new ModelAndView("busqueda/listar","productos",searchService.listarBusqueda(busqueda));
		
	}

}
